package com.aw.guiguzi.adapter

import com.aw.guiguzi.R
import com.aw.guiguzi.bean.NumItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

class NumHandleInputAdapter :
    BaseQuickAdapter<NumItemBean, BaseViewHolder>(R.layout.adapter_num_handle_input) {
    private var mList: MutableList<NumItemBean>? = ArrayList()

    init {
        if (mList == null) {
            mList = ArrayList()
        }
    }

    override fun convert(helper: BaseViewHolder, bean: NumItemBean) {
        helper.setText(R.id.tv_nums, bean.name)
        if (bean.isChecked) {
            helper.setBackgroundRes(R.id.tv_nums, R.drawable.aw_bg_blue)
                .setTextColor(R.id.tv_nums, mContext.resources.getColor(R.color.white))
        } else {
            helper.setBackgroundRes(R.id.tv_nums, R.drawable.aw_bg_gray)
                .setTextColor(R.id.tv_nums, mContext.resources.getColor(R.color.black))
        }
    }

    fun addAllData(dataList: MutableList<NumItemBean>?) {
        mList = dataList
        setNewData(mList)
        notifyDataSetChanged()
    }

    fun clearData() {
        if (mList != null) {
            val startPosition = 0 //hasHeader is 1
            val preSize = mList!!.size
            if (preSize > 0) {
                mList!!.clear()
                notifyItemRangeRemoved(startPosition, preSize)
            }
        }
    }
}